package com.LLL;

import com.google.gson.Gson;

import javax.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;


public class Util {

    public static void writerData(HttpServletResponse resp, List list){
        //9、返回数据
        resp.setContentType("application/json; charset=utf-8");
        //需要添加依赖
        Gson gson = new Gson();
        //将list对象转为JSON格式字符串
        String result = gson.toJson(list);
        //输出转换后的字符串数据
        try {
            resp.getWriter().println(result);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    /** 生成订单的编号*/
    public static String createOrderId(){
        LocalDateTime now = LocalDateTime.now();
        return ""+now.getYear() + (now.getMonthValue()<10?"0"+ now.getMonthValue():now.getMonthValue())
                + (now.getDayOfMonth()<10?"0"+now.getDayOfMonth():now.getDayOfMonth())
                +now.toLocalTime().toString().replace(".","").replace(":","");
    }
}
